package com.xzx.springbootredis.controller;

import com.xzx.springbootredis.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * 库存处理
 */
@RestController
@RequestMapping("stock")
public class SetStockController {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    //设置库存
    @PostMapping("set")
    public JsonResult set(@RequestParam("id") int id, @RequestParam("stock") int stock) {
        //用kv字符串
        stringRedisTemplate.opsForValue().set("goods-stock:"+id, String.valueOf(stock));
        return JsonResult.success("设置成功",null);
    }
}
